import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'element-ui/lib/theme-chalk/index.css'

import {
  Dialog,
  Input,
  Button,
  Form,
  FormItem,
  Message,
  MessageBox,
  Icon,
  Table,
  TableColumn,
  Pagination,
  Popover
} from 'element-ui'
Vue.use(Dialog)
Vue.use(Input)
Vue.use(Button)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Icon)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Pagination)
Vue.use(Popover)

Vue.prototype.$message = Message
Vue.prototype.$msgbox = MessageBox

Vue.config.productionTip = false

// 路由守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('userToken')
  if (token) {
    next()
  } else {
    if (to.meta.requireAuth) {
      Message('请登录')
    } else {
      next()
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
